www.gusucode.com > Augsburg Biosignal Toolbox源码程序 > matlab代做 修改 程序Augsburg Biosignal Toolbox/程序与说明/程序与说明/数据/Augsburg大学原始数据及说明/matlab/plot/aubt_classBoundPlot.m
function aubt_classBoundPlot (ahandle, data, labels, method, opt, resolution, colors, plotdim) % Trains the classificator identified by method with data and labels and % plots the decision boundary. Therefor data is projected in a two % dimensional space using fisher transformation and normalized in a range % between 0 and 1. The feature space is plotted in x and y direction % between [-0.2, 1.2]. % % aubt_classBoundPlot (ahandle, data, labels, method, opt, resolution, colors, opt) % % input: % ahandle: axes handle of the current figure % data: feature matrix (one sample per row) % labels: label vector % method: name of the classifier % opt: options for the classifier % resolution: the resolution of the plotted feature space % e.g. 50 produces a meshgrid of size 71x71 % 100 produces a meshgrid of size 141x141 and so on % colors: matrix with color values % one color [r, g, b] per row for each label % plotdim: '2D' for a 2 dimensional plot (default) % '3D' for a 3 dimensional plot % 'both' for both, a 2 and a 3 dimensional plot in one figure % % 2005, Johannes Wagner <go.joe@gmx.de> if nargin < 8 | isempty (plotdim) plotdim = '2D'; end if size (data, 2) < 2 error 'number of features values in data matrix must be at least 2 per row' end % project data if necessary if size (data, 2) > 2 data = aubt_fisher (data, labels, 2); end % number of classes csize = max (labels); % normalize data between [0..1] data = aubt_rangeNorm (data, 0, 1); % generate grid x = -0.2:1/resolution:1.2; [X Y] = meshgrid (x,x); % classify data switch method case {'linear'} px = aubt_lindiscr ([X(:) Y(:)], data, labels); px = px - min (min (px)); case {'quadratic'} px = aubt_quaddiscr ([X(:) Y(:)], data, labels); px = px - min (min (px)); case {'mahalanobis'} px = aubt_mahad ([X(:) Y(:)], data, labels); px = px - min (min (px)); case {'euclide'} px = aubt_eucld ([X(:) Y(:)], data, labels); px = px - min (min (px)); case {'ffnet'} px = aubt_ffnet ([X(:) Y(:)], data, labels, opt(1), opt(2), opt(3)); case {'knn'} px = aubt_knn ([X(:) Y(:)], data, labels, opt(1)); otherwise error ('Unknown classification method') end % plot decision boundaries axes (ahandle); [vals, postl] = max (px, [], 2); con = reshape (postl, size (X)); colormap (colors); switch plotdim case {'2D'} hold on; axis ([-0.2, 1.2, -0.2, 1.2]); view (0, 90); [C,h] = contourf (X, Y, con, 1:csize); for i = 1:csize cdata = aubt_getClassData (data, labels, i); scatter (cdata(:,1), cdata(:,2), 3, 'MarkerFaceColor', colors(i,:), 'MarkerEdgeColor', 'k'); end hold off; case {'3D'} hold on; axis ([-0.2, 1.2, -0.2, 1.2, 0, (max (max (px)))]); view (-30, 20); pxx = zeros (size (X, 1), size (X, 2), csize); for i = 1:csize pxx(:,:,i) = reshape (px(:,i), size(X)); end for i = 1:csize mp = mesh (X, Y, pxx(:,:,i)); set (mp, 'EdgeColor', colors(i,:)); end hold off; case{'both'} subplot (1,2,2); hold on; axis ([-0.2, 1.2, -0.2, 1.2, 0, (max (max (px)))]); view (-30, 20); pxx = zeros (size (X, 1), size (X, 2), csize); for i = 1:csize pxx(:,:,i) = reshape (px(:,i), size(X)); end for i = 1:csize mp = mesh (X, Y, pxx(:,:,i)); set (mp, 'EdgeColor', colors(i,:)); end hold off; subplot (1, 2, 1); hold on; axis ([-0.2, 1.2, -0.2, 1.2]); view (0, 90); [C,h] = contourf (X, Y, con, 1:csize); for i = 1:csize cdata = aubt_getClassData (data, labels, i); plot (cdata(:,1), cdata(:,2), 'Marker', 'o', 'MarkerSize', 3, 'LineStyle', 'none', 'MarkerFaceColor', colors(i,:), 'MarkerEdgeColor', 'k'); end hold off; otherwise error ('Unknown plot dimension option') end